package com.xcity.game.battle.pve.template;

import naga.x.App;
import naga.x.game.template.Template;
import naga.x.game.template.TemplateException;
import naga.x.game.template.TemplateService;
import naga.x.game.template.annotation.Binding;
import naga.x.game.template.annotation.Excel;

/**
 * 章节宝箱
 * @author shipeng.zhu
 *
 */
@Excel(value = "stage.xlsx", sheetName = "章节宝箱")
public class StagePageTemplate extends Template {
	
	public static int MAX_BOX_COUNT = 3;
	
	@Deprecated
	/** 第几页 */
	protected int page;

	/** 普通关星数宝箱掉落组 普通[0~2]精英[3~5]*/
	protected int[] starBoxId;
	
	/** 地图 资源 */
	protected String[] mapStr;
	
	/** 需要的星数  普通[0~2]精英[3~5]*/
	protected int[] needStar;
	
	/** 章节名字 */
	protected String pageName;
	
	/** 章在区中的坐标x */
	protected int areaX;
	
	/** 章在区中的坐标y */
	protected int areaY;

	/** 区号 */
	protected int area;
	
	protected StageAreaTemplate areaTemp;
	
	@Deprecated
	public int getPage() {
		return page;
	}

	@Deprecated
	public void setPage(int page) {
		this.page = page;
	}

	public int[] getStarBoxId() {
		return starBoxId;
	}

	public void setStarBoxId(int[] starBoxId) {
		this.starBoxId = starBoxId;
	}

	public String[] getMapStr() {
		return mapStr;
	}

	public void setMapStr(String[] mapStr) {
		this.mapStr = mapStr;
	}

	public int[] getNeedStar() {
		return needStar;
	}

	public void setNeedStar(int[] needStar) {
		this.needStar = needStar;
	}
	
	public String getPageName() {
		return pageName;
	}

	public void setPageName(String pageName) {
		this.pageName = pageName;
	}

	public int getAreaX() {
		return areaX;
	}

	public void setAreaX(int areaX) {
		this.areaX = areaX;
	}

	public int getAreaY() {
		return areaY;
	}

	public void setAreaY(int areaY) {
		this.areaY = areaY;
	}

	public int getArea() {
		return area;
	}

	public void setArea(int area) {
		this.area = area;
	}

	@Override
	public void validate() throws TemplateException {
		if(starBoxId == null || starBoxId.length != 6){
			throw new TemplateException("stage.xlsx星数奖励配置错误->id=" + id);
		}
		if(mapStr == null || mapStr.length != 2){
			throw new TemplateException("stage.xlsx地图配置错误->id=" + id);
		}
		if(needStar == null || needStar.length != 6){
			throw new TemplateException("stage.xlsx需要星数配置错误->id=" + id);
		}
		if(area > StageAreaTemplate.MAX_ID || area < 1){
			throw new TemplateException("stage.xlsx章节区域配置错误->id=" + id);
		}
	}
	
	public StageAreaTemplate getAreaTemplate(){
		if(areaTemp == null){
			TemplateService service = App.getApp().getServiceManager().get(TemplateService.class);
			areaTemp = service.get(StageAreaTemplate.class, area);
		}
		return areaTemp;
	}
}
